#ifndef __CACHE_H__
#define __CACHE_H__

#include <string>
#include <unordered_map>
#include <list>
#include <functional>

using namespace std;
using iter=list<pair<string,string>>::iterator;

class Cache
{
public:
    Cache(int num=10); 
    Cache(const Cache& cache);
    void addElement(const string& key,const string &value);
    void readFromFile(const string& filename);
    void writeToFile(const string& filename);
    void update(const Cache& rhs);
    void selfUpdate();
    list<pair<string,string>> getLRUlist();
    unordered_map<string,iter> gethashMap();
private:
    void build_hashMap();
    void LRUadd(list<pair<string,string>> list,const string& key,const string& value);
private:
    unordered_map<string,iter> _hashMap;//迭代器map
    list<pair<string,string>> _LRUlist;//数据list
    list<pair<string,string>> _updateData;//更新list
    int _size;
};

#endif
